package org.ihelpuoo.weboo.upload;

import java.io.File;

public class FileItem
{
	private String	originalPath;
	private String	extension;
	private File	file;
	private String	originalName;
	private String	contentType;

	public String getContentType()
	{
		return contentType;
	}

	void setContentType(String contentType)
	{
		this.contentType = contentType;
	}

	public File getFile()
	{
		return file;
	}

	void setFile(File file)
	{
		this.file = file;
	}

	public String getOriginalName()
	{
		return originalName;
	}

	public String getOriginalPath()
	{
		return originalPath;
	}

	public String getExtension()
	{
		return extension;
	}

	void setOriginalPath(CharSequence path)
	{
		originalPath = (null == path ? null : path.toString());
		if (null != originalPath && originalPath.length() > 1)
		{
			int offset = 1;
			if (originalPath.charAt(0) != '\\' && originalPath.charAt(0) != '/')
				offset = 0;

			int pos = originalPath.lastIndexOf('.');
			if (pos >= 0)
			{
				extension = originalPath.substring(pos + 1).toLowerCase();
				int i = pos - 1;
				for (; i > 0; i--)
				{
					char c = originalPath.charAt(i);
					if (c == '\\' || c == '/')
						break;
				}
				this.originalName = originalPath.substring(i + offset,pos);
			}
			else
			{
				this.originalName = originalPath;
				this.extension = null;
			}
		}
	}
}
